package cn.bincker.mycaptcha.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class RequestUtils {
    public static String getRequestPath(){
        var requestAttributes = RequestContextHolder.getRequestAttributes();
        if(!(requestAttributes instanceof ServletRequestAttributes)) return "";
        var request = ((ServletRequestAttributes) requestAttributes).getRequest();
        var port = "";
        if(request.getServerPort() != 80 && request.getServerPort() != 443) port = ":" + request.getServerPort();
        return request.getScheme() + "://" + request.getServerName() + port + request.getServletPath() + "/";
    }
}
